﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.CompilerServices;
    using System.Web.UI.WebControls;

    public class AdminReportPopup : BaseModule
    {
        [AccessedThroughProperty("dgResults")]
        private DataGrid _dgResults;
        [AccessedThroughProperty("lblMessage")]
        private Label _lblMessage;

        public AdminReportPopup()
        {
            base.Load += new EventHandler(this.Page_Load);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SQLReportController controller = new SQLReportController();
                this.lblMessage.Text = DotNetNuke.Services.Localization.Localization.GetString("QueryError", this.LocalResourceFile);
                if ((this.Request.QueryString["REPID"] != "") && Versioned.IsNumeric(this.Request.QueryString["REPID"].ToString()))
                {
                    int reportID = Conversions.ToInteger(this.Request.QueryString["REPID"].ToString());
                    NB_Store_SQLReportInfo sQLReport = controller.GetSQLReport(reportID);
                    if ((sQLReport != null) && (sQLReport.SQL != ""))
                    {
                        this.lblMessage.Text = "";
                        sQLReport.SQL = controller.insertParams(reportID, this.UserId, this.PortalId, this.Request, sQLReport.SQL, SharedFunctions.GetCurrentCulture());
                        string formXMLData = SharedFunctions.getStoreCookieValue(this.PortalId, "SQLFORMREPORT", "XMLDATA");
                        sQLReport.SQL = controller.insertFormParams(reportID, sQLReport.SQL, formXMLData);
                        string str2 = "";
                        str2 = controller.runXSL(sQLReport);
                        if (str2 != "")
                        {
                            if (str2 != "HIDE_XSL_OUTPUT")
                            {
                                Label lblMessage = this.lblMessage;
                                lblMessage.Text = lblMessage.Text + str2;
                            }
                        }
                        else
                        {
                            if (sQLReport.ShowSQL)
                            {
                                this.lblMessage.Text = sQLReport.SQL + "<br /><hr />";
                            }
                            controller.popDataGridSQL(sQLReport.SQL, this.dgResults);
                        }
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                this.lblMessage.Text = exception1.ToString() + "<hr />";
                ProjectData.ClearProjectError();
            }
        }

        protected virtual DataGrid dgResults
        {
            get
            {
                return this._dgResults;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._dgResults = value;
            }
        }

        protected virtual Label lblMessage
        {
            get
            {
                return this._lblMessage;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                this._lblMessage = value;
            }
        }
    }
}

